home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4168 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: mail2news.demon.co.uk!hpl3sn03.cern.ch
  2. From: Dan Pop <danpop@mail.cern.ch>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Fastest way to computer log(base2) of x?
  5. Date: Fri, 2 Feb 1996 13:38:45 +0100
  6. Organization: CERN European Lab for Particle Physics
  7. Message-ID: <9602021238.AA01292@dxmint.cern.ch>
  8. References: <4e61iu$p6e@villa.fc.net> <4e6p7t$1n72@cymbal.aix.calpoly.edu> <4e8r54$n8q@ns.RezoNet.NET>,<4e9bl4$3ccp@cymbal.aix.calpoly.edu> <DM0AKu.A2H@news.cern.ch> <4eqvr1$7tn@news.microsoft.com>
  9. X-NNTP-Posting-Host: hpl3sn03.cern.ch
  10. X-Newsreader: NN version 6.5.0 #7 (NOV)
  11. X-Mail2News-Path: dxmint.cern.ch!hpl3sn03.cern.ch
  12.  
  13. a-cnadc@microsoft.com (Dann Corbit) writes:
  14.  
  15. >Just a note that none of theses methods really find the base 2
  16. >log of a number unless the number is a power of 2.  It is only
  17. >a crude approximation of the log most of the time.  You are 
  18. >finding the highest bit, that is all.  NOT the log base 2.
  19.  
  20. And this is precisely what the original poster was asking for:
  21.  
  22.     I am trying to find out what could be the fastest way to compute
  23.     the position of the highest bit in any given integer -- basically, the
  24.     logarithm to the base 2 of any number.
  25.  
  26. The position of the highest bit happens to be (int)(log base 2) if the
  27. bit positions are counted from zero (i.e. the lsb is bit 0).
  28.  
  29. Dan
  30. -- 
  31. Dan Pop
  32. CERN, CN Division
  33. Email: danpop@mail.cern.ch 
  34. Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
  35.